<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta charset="utf-8">
    <title>物品记录管理</title>
    <link rel="icon" href="../fffff.ico">
    <link rel="stylesheet" href="../layui/css/layui.css"/>
    <link rel="stylesheet" href="../css/my.css"/>
</head>
<body>
<ul class="layui-nav layui-bg-green " lay-filter="" style="width: 1900px">

    <li class="layui-nav-item layui-this my" id="user">你好：</li>
    <li class="layui-nav-item"><a href="/changepwd">修改密码</a></li>
    <li class="layui-nav-item"><a onclick="log()" style="cursor: pointer;">退出</a></li>

</ul>
<div style="width: 1850px;background-color: #ffffff;">
    <div style="float: left;margin-top: 14px;">
        <ul class="layui-nav layui-nav-tree layui-inline" lay-filter="demo"
            style="margin-right: 10px;height: 750px;width: 139px">
            <li class="layui-nav-item"><a href="/info">物品管理</a></li>
            <li class="layui-nav-item"><a href="/thing">物品图片</a></li>
            <li class="layui-nav-item" style="background-color: #4e5465;"><a href="/eve">每日的事</a></li>
            <li class="layui-nav-item"><a href="/password">密码管理</a></li>
        </ul>
    </div>
    <div style="margin-left: 25px;padding-top: 15px;">
        <button type="button" class="layui-btn layui-btn-normal layui-btn-radius" onclick="insert()">添加每日要做的事</button>
    </div>
    <div style="float: left;margin-left: 0px;background-color: #ffffff;">
        <table class="layui-hide " id="test" lay-filter="t" lay-data="{id: 'idTest'}"></table>
    </div>
</div>


<script src="../layui/layui.all.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script>


<!--<script type="text/html" id="toolbarDemo">-->
<!--    <div class="">-->
<!--        <button class="layui-btn layui-btn-sm" lay-event="getCheckData">删除选中行</button>-->

<!--    </div>-->

<!--</script>-->
<script type="text/html" id="toolbarDemo">
    <div class="">
        <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="getCheckData">删除选中行</button>
<!--        <button class="layui-btn layui-btn-sm" lay-event="DeleteEve" style="">删除每页</button>-->
    </div>
    <div class="">

    </div>
</script>
<!--lay.js必须在删除下面-->
<script >
    layui.use('table', function () {
        var table = layui.table;

        table.render({
            elem: '#test'
            , url: '/thing/list'
            , toolbar: '#toolbarDemo'
            // ,height: '35'
            , cols: [[
                {type: 'checkbox'},
                {
                    field: 'thing', width: 250, title: '事件', templet: function (d) {
                        if (d.state == 0) {
                            return '<h5 >' + d.thing + '</h5>'
                        }
                        return '<h5 class="h33">' + d.thing + '</h5>'
                    }
                }

                , {fixed: 'right', width: 250, toolbar: '#barDemo'}
            ]],
            id: 'idTest',
            parseData: function (res) { //将原始数据解析成 table 组件所规定的数据

                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.count, //解析数据长度
                    "data": res.data //解析数据列表
                };
            }
            , hide: true
            , skin: 'nob'
            , method: "post"
            , page: true
            , limits: [1, 2, 3, 4, 5]
            , limit: 5
        });
        //头工具栏事件
        table.on('toolbar(t)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.confirm('点击确定删除?', {icon: 3, title: '提示'}, function (index) {
                        //do something
                        $.ajax({
                            url: "/thing/deletes",
                            type: 'POST',
                            data: JSON.stringify(data),
                            dataType: 'json',
                            contentType: 'application/json;charset=UTF-8',
                            success: function (data) {
                                if (data.success) {
                                    layer.msg(data.msg);
                                    $(".layui-laypage-btn").trigger("click");
                                } else {
                                    layer.msg(data.msg);
                                }
                            }
                        });
                        layer.close(index);
                    });


                    // layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：' + data.length + ' 个');
                    break;
                case 'DeleteEve':
                    var data = checkStatus.data;
                    console.log(checkStatus);
                    console.log(index);
                    console.log(obj.limit);
                    console.log(table.limit);
                    console.log(table.size);
                    layer.msg('选中了：' + data.length + ' 个');
                    break;
                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            }
            ;
        });
        //监听工具条
        table.on('tool(t)', function (obj) {
                //console.log(obj);
                console.log(obj.data.thingId);
                var data = obj.data;
                if (obj.event === 'del') {
                    layer.confirm('点击确定删除', function (index) {
                        obj.del();
                        $.ajax({
                            url: "/thing/delete/" + obj.data.thingId,
                            type: 'POST',
                            contentType: false,
                            processData: false,
                            cache: false,
                            success: function (data) {
                                if (data.success) {
                                    // $(".layui-laypage-btn").trigger("click");
                                    layer.msg('删除成功');

                                } else {
                                    layer.msg(data.msg);
                                }
                            }
                        });
                        layer.close(index);
                    });
                } else if (obj.event === 'edit') {
                    // layer.alert('编辑行：<br>' + JSON.stringify(data))
                    layer.open({
                        type: 2,
                        content: '/insertthing?thingId=' + obj.data.thingId,
                        area: ['450px', '250px'],
                        resize: false,
                        cancel: function () {
                            layui.use('table', function () {
                                var table = layui.table;

                                table.render({
                                    elem: '#test'
                                    , url: '/thing/list'
                                    , toolbar: '#toolbarDemo'
                                    // ,height: '35'
                                    , cols: [[
                                        // {type: 'checkbox'},
                                        {
                                            field: 'thing', width: 250, title: '事件', templet: function (d) {
                                                if (d.state == 0) {
                                                    return '<h5 >' + d.thing + '</h5>'
                                                }
                                                return '<h5 class="h33">' + d.thing + '</h5>'
                                            }
                                        }

                                        , {fixed: 'right', width: 250, toolbar: '#barDemo'}
                                    ]],
                                    id: 'idTest',
                                    parseData: function (res) { //将原始数据解析成 table 组件所规定的数据

                                        return {
                                            "code": res.code, //解析接口状态
                                            "msg": res.msg, //解析提示文本
                                            "count": res.count, //解析数据长度
                                            "data": res.data //解析数据列表
                                        };
                                    }
                                    , hide: true
                                    , skin: 'nob'
                                    , page: true
                                    , method: "post"
                                    , limits: [1,2,3,4,5]
                                    , limit: 5
                                });
                            })
                        }
                    })
                } else {
                    console.log(obj.data.thingId);

                    $.ajax({
                        url: "/thing/change/" + obj.data.thingId,
                        type: 'POST',
                        contentType: false,
                        processData: false,
                        cache: false,
                        success: function (data) {
                            if (data.success) {
                                // window.parent.location.reload();
                                $(".layui-laypage-btn").trigger("click");
                            } else {
                                layer.msg(data.msg);
                            }
                        }
                    })
                    setTimeout(function () {
                        layui.use('table', function () {
                            var table = layui.table;

                            table.render({
                                elem: '#test'
                                , url: '/thing/list'
                                , toolbar: '#toolbarDemo'
                                // ,height: '35'
                                , cols: [[
                                    {type: 'checkbox'},
                                    {
                                        field: 'thing', width: 250, title: '事件', templet: function (d) {
                                            if (d.state == 0) {
                                                return '<h5 >' + d.thing + '</h5>'
                                            }
                                            return '<h5 class="h33">' + d.thing + '</h5>'
                                        }
                                    }
                                    // , {field: 'quantity', width: 80, title: '数量'}
                                    // , {field: 'goodPlace', width: 300, title: '存放地点'}
                                    // , {field: 'createTime', width: 200, title: '创建时间'}
                                    // , {field: 'updateTime', width: 200, title: '更新时间'}
                                    // , {field: 'detail', title: '简介'}
                                    , {fixed: 'right', width: 250, toolbar: '#barDemo'}
                                ]],
                                id: 'idTest',
                                parseData: function (res) { //将原始数据解析成 table 组件所规定的数据
                                    // $('.layui-table .layui-table-cell > span').css({'font-weight': 'bold'});//表头字体样式
                                    // /*$('th').css({'background-color': '#5792c6', 'color': '#fff','font-weight':'bold'}) 表头的样式 */
                                    // $('th').hide();//表头隐藏的样式
                                    // // $('.layui-table-page').css('margin-top','40px');//页码部分的高度调整
                                    // $('td').css({'border': 'none'});//设置td无边框
                                    return {
                                        "code": res.code, //解析接口状态
                                        "msg": res.msg, //解析提示文本
                                        "count": res.count, //解析数据长度
                                        "data": res.data //解析数据列表
                                    };
                                }
                                , hide: true
                                , skin: 'nob'
                                , page: true
                                , method: "post"
                                , limits: [1, 2, 3, 4, 5]
                                , limit: 5
                            });
                        })
                    }, 500);


                    // if ($("#b").text() == "取消完成") {
                    //
                    //     $("#b").removeClass('layui-btn-primary');
                    //     $("#b").text('点击完成');
                    // } else {
                    //     $("#b").addClass('layui-btn-primary');
                    //     $("#b").text('取消完成');
                    //
                    // }
                }
            }
        );
    });


    function log() {

        layer.confirm('点击确定退出登录', {icon: 3, title: '提示'}, function (index) {
            //do something
            $.ajax({
                url: "/user/logout",
                type: 'POST',
                contentType: false,
                processData: false,
                cache: false,
                success: function (data) {
                    if (data.success) {
                        layer.msg('退出成功');
                        setTimeout(function () {
                            window.location.href = "/login";
                        }, 800);
                    } else {
                        layer.msg(data.msg);
                    }
                }
            });
            layer.close(index);
        });
    }

    function insert() {
        layer.open({
            type: 2,
            content: '/insertthing',
            area: ['450px', '250px'],
            resize: false,
            cancel: function () {
                layui.use('table', function () {
                    var table = layui.table;
                    table.reload('idTest', {
                        url: '/thing/list'
                        , where: {} //设定异步数据接口的额外参数
                        //,height: 300
                    });
                })

            }, end: function () {
                $(".layui-laypage-btn").trigger("click");
            }
            //这里content是一个普通的String
        });
    }

    function update(id) {
        layer.open({
            type: 2,
            content: '/insert?goodId=' + id,
            area: ['530px', '450px'],
            resize: false,
            cancel: function () {
                $.ajax({
                    url: "/goods/info",
                    type: 'POST',
                    dataType: 'json',
                    contentType: false,
                    processData: false,
                    cache: false,
                    success: function (data) {
                        if (data.success) {
                            var html = "";
                            data.data.map(function (item, index) {
                                html += "<tr><td>" + item.goodName + "</td><td>" + item.quantity + "</td><td>" + item.goodPlace + "</td><td>" + item.createTime
                                    + "</td><td>" + item.updateTime + "</td><td>" + item.detail + "</td><td>" +
                                    "						<a class=\"layui-btn  layui-btn-sm\" onclick=\"update(" + item.goodId + ")\">修改</a>" +
                                    "						<a class=\"layui-btn layui-btn-danger layui-btn-sm\" onclick=\"del(" + item.goodId + ")\">删除</a>" + "</td></tr>"
                                $(".tb").html(html);
                            })
                        } else {
                            layer.msg(data.msg);
                        }
                    }
                })
            }, end: function () {
                $(".layui-laypage-btn").trigger("click");

            }
            //这里content是一个普通的String
        });
        // window.location.href = "/insert?goodId="+id;
    }


    $("#search").click(function () {
        // layer.msg($("#searin").val());
        var table = layui.table;

        table.reload('idTest', {
            url: '/goods/page',
            where: {
                name: $("#searin").val()
            },
            page: {
                curr: 1
            }
        });

    })
    $(function () {
        $.ajax({
            url: "/goods/name",
            type: 'POST',
            dataType: 'json',
            contentType: false,
            processData: false,
            cache: false,
            success: function (data) {
                if (data.success) {

                    $("#user").text("你好:" + data.data.userName);
                } else {
                    layer.msg(data.msg);
                }
            }
        });


    })



</script>



<script type="text/html" id="barDemo">
    <!--    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>-->
    <!--    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
    {{#  if(d.state === 0){ }}
    <button style="margin-left: 26px;" type="button" class="layui-btn layui-btn-xs layui-btn-radius " lay-event="wan"
             >
        点击完成
    </button>
    {{#  } else { }}
    <button style="margin-left: 26px;" type="button" class="layui-btn layui-btn-xs layui-btn-radius layui-btn-primary"
            lay-event="wan" >
        取消完成
    </button>
    {{#  } }}

    <button style="margin-left: 26px;" type="button" class="layui-btn layui-btn-xs layui-btn-danger layui-btn-radius"
            lay-event="del">
        删除
    </button>
    <button style="margin-left: 6px;" type="button" class="layui-btn layui-btn-xs layui-btn-warm layui-btn-radius"
            lay-event="edit">编辑
    </button>

</script>
</body>


</html>
